package com.lagou.jdbc02;

import com.lagou.utils.JDBCUtils;
import org.junit.Test;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

/**
 * @Author wsl
 * @Date 2021/8/18 22:31
 * @Project_Name mysql
 */
public class TestDQL {

    /**
     * 查询操作
     */
    @Test
    public void testSelect() throws SQLException {

        Connection con = JDBCUtils.getConnection();

        Statement statement = con.createStatement();

        String sql = "select * from jdbc_user where username='admin2'";
        ResultSet resultSet = statement.executeQuery(sql);

        //处理结果集
        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String username = resultSet.getString("username");
            String password = resultSet.getString("password");
            String birthday = resultSet.getString("birthday");

            System.out.println(id+" : "+username+" : "+password+" : "+birthday);
        }

        JDBCUtils.close(con, statement,resultSet);

    }
}
